import java.util.ArrayList;
import java.util.List;

public class 括号生成 {


    public static void main(String[] args) {
        

        System.out.println(generateParenthesis(1));
    }

    private static List<String> result = new ArrayList<>();
    private static char[] path;

    public static List<String> generateParenthesis(int n) {
        
        path = new char[2*n];

        dfs(n,0,0,0);

        return result;
    }

    private static void dfs(int n,int left,int right,int i){

        if(i == 2*n){

            result.add(new String(path));

            return;
        }

        if(left < n){

            path[i] = '(';
            dfs(n, left+1, right, i+1);
        }

        if(right < left){

            path[i] = ')';
            
            dfs(n, left, right+1, i+1);
        }

    }
}
